package cn.coisini.api.admin;

import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.dto.ArticleDto;
import cn.coisini.model.pojo.Article;
import cn.coisini.model.vo.QueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 文章接口API
 */
@Tag(name = "文章接口API", description = "新增、查询")
@RequestMapping("/api/v1/article")
@Validated
public interface ArticleControllerApi {

    @PreAuthorize("hasAuthority('article:add')")
    @Operation(summary = "新增文章接口")
    @PostMapping("/add")
    Result<ResultEnum> addArticle(
            @RequestBody
            @Validated({ArticleDto.Add.class})
            ArticleDto articleDto);

    @PreAuthorize("hasAuthority('article:list')")
    @Operation(summary = "条件分页 文章列表查询")
    @GetMapping("/list")
    Result<Object> getArticleList(QueryVo queryVo);

    @PreAuthorize("hasAuthority('article:get')")
    @Operation(summary = "根据文章id查询文章")
    @GetMapping("/get")
    Result<Article> getArticleById(String articleId);

    @PreAuthorize("hasAuthority('article:delete')")
    @Operation(summary = "根据文章id删除文章")
    @DeleteMapping("/delete")
    Result<ResultEnum> deleteArticle(String articleId);

    @PreAuthorize("hasAuthority('article:update')")
    @Operation(summary = "根据文章id更新文章")
    @PutMapping("/update")
    Result<ResultEnum> updateArticle(
            @RequestBody
            @Validated({ArticleDto.Update.class})
            ArticleDto articleDto);

    @PreAuthorize("hasAuthority('article:count')")
    @Operation(summary = "根据分类id查询文章数量")
    @GetMapping("/count")
    Long getArticleCountByCategoryId(String categoryId);

    @PreAuthorize("hasAuthority('article:listByIds')")
    @Operation(summary = "根据分类ids查询文章")
    @GetMapping("/listByIds")
    List<Article> getArticleListByIds(List<String> categoryIds);

    @PreAuthorize("hasAuthority('article:listByTagId')")
    @Operation(summary = "根据标签id查询文章")
    @GetMapping("/listByTagId")
    List<Article> getArticleListFromTag(String tagId);
}
